﻿using System;
using System.Text;

namespace OST.Shared.SharedTypes
{
    /// <summary>
    /// represents the frame-configuration
    /// </summary>
    public class FrameConfiguration
    {      
        #region CTOR

        public FrameConfiguration()
        {
            Offset = double.NaN;
            MotorAlign = enumMotorAlignment.None;
            Body = 0;
            Stroke = 0;
            Arm = 0;
            Leg = 0;
            WindAlarm = 5;
        }
        #endregion

        #region Properties
        
        /// <summary>
        /// Offset angle in degree 
        /// </summary>
        public double Offset { get; set; }

        /// <summary>
        /// used motor-alignment
        /// </summary>
        public enumMotorAlignment MotorAlign { get; set; }

        /// <summary>
        /// motor body in mm
        /// </summary>
        public int Body { get; set; }

        /// <summary>
        /// motor stroke in mm
        /// </summary>
        public int Stroke { get; set; }

        /// <summary>
        /// frame-leg in mm
        /// </summary>
        public int Leg { get; set; }

        /// <summary>
        /// frame-arm in mm
        /// </summary>
        public int Arm { get; set; }

        /// <summary>
        /// wind-speed-threshold-(alarm), in m/s
        /// </summary>
        public double WindAlarm { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// validates the this instance
        /// </summary>
        public void Validate()
        {
            if (MotorAlign == enumMotorAlignment.None)
            {
                throw new OSTException("config-frame: MotorAlignment is None");
            }

            if (Body == 0
                || Stroke == 0
                || Arm == 0
                || Leg == 0)
            {
                throw new OSTException("config-frame: geometry invalid");
            }

            if (WindAlarm < 0 || WindAlarm > 12)
            {
                throw new OSTException("config-frame: WindAlarm invalid <0 or >12");
            }
        }

        public override string ToString()
        {
            var str = new StringBuilder();
            
            str.AppendLine();
            str.AppendLine("Offset: " + Offset);
            str.AppendLine("MotorAlign: " + MotorAlign);
            str.AppendLine("Body: " + Body);
            str.AppendLine("Stroke: " + Stroke);
            str.AppendLine("Leg: " + Leg);
            str.AppendLine("Arm: " + Arm);
            str.AppendLine("WindAlarm: " + WindAlarm);

            return str.ToString();
        }

        #endregion
    }
}
